import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { envParse, parseLoadedEnv } from 'vite-plugin-env-parse'

export default defineConfig(({ mode }) => {
  const vite_env = parseLoadedEnv(loadEnv(mode, './'))
  console.log('.env', vite_env)

  return {
    plugins: [vue(), envParse()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      // host: '0.0.0.0',
      // port: 8081,
      proxy: {
        '/api': {
          target: vite_env.VITE_VX_BOSS_API_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
        '/wapi': {
          target: vite_env.VITE_ZHIPIN_WAPI_URL,
          changeOrigin: true
          // rewrite: (path) => path
        }
      }
    }
  }
})
// https://vitejs.dev/config/
